package com.tao.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tao.dao.ArticleDAO;
import com.tao.dao.CategoryDAO;
import com.tao.service.ArticleService;
import com.tao.to.KArticleTO;
import com.tao.to.KCategoryTO;

@Service
public class ArticleServiceImpl implements ArticleService{
	
	@Autowired
	private ArticleDAO articleDAO;
	
	@Autowired
	private CategoryDAO categoryDAO;
	
	private List<KCategoryTO> categoryList;
	
	private static ArticleServiceImpl _instance;
	
	private ArticleServiceImpl(){}
	
	public static ArticleServiceImpl getIntance(){
		return _instance;
	}
	
	public List<KArticleTO> getArticlesByCategory(int category){
		List<KArticleTO> articleList = articleDAO.getArticlesByCategory(category); 
		if(articleList == null){
			articleList = new ArrayList<KArticleTO>();
		}
		
		if(articleList.size() < 10){
			for(int i = 0; i < 10 - articleList.size(); i++){
				articleList.add(new KArticleTO());
			}
		}
		return articleList;
	}
	
	public List<KCategoryTO> getCategoryList() {
		if(_instance == null){
			categoryList = categoryDAO.getCategory();
			_instance = this;
		}
		return categoryList;
	}


	@Override
	public void saveArticle(KArticleTO karticle) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteArticle(String karticleId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateArticle(KArticleTO karticle) {
		// TODO Auto-generated method stub
		
	}
	
}
